﻿
    using Chain.BLL;
    using Chain.Model;
    using System;
    using System.Data;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public partial class ShopList : PageBase
    {

        public bool isopen = PubFunction.curParameter.bolIsSettlement;


        private void BindShopList(string strWhere)
        {
            Chain.BLL.SysShop Shop = new Chain.BLL.SysShop();
            int Counts = this.NetPagerParameter.RecordCount;
            string strSql = " ShopID>0";
            strSql = strSql + strWhere;
            DataTable db = Shop.GetListSP(this.NetPagerParameter.PageSize, this.NetPagerParameter.CurrentPageIndex, out Counts, new string[] { strSql }).Tables[0];
            this.NetPagerParameter.RecordCount = Counts;
            this.NetPagerParameter.CustomInfoHTML = string.Format("<div class=\"results\"><span>当前第{0}/{1}页 共{2}条记录 每页{3}条</span></div>", new object[] { this.NetPagerParameter.CurrentPageIndex, this.NetPagerParameter.PageCount, this.NetPagerParameter.RecordCount, this.NetPagerParameter.PageSize });
            this.gvShopListProfession.DataSource = db;
            this.gvShopListProfession.DataBind();
            PageBase.BindSerialRepeater(this.gvShopListProfession, this.NetPagerParameter.PageSize * (this.NetPagerParameter.CurrentPageIndex - 1));
        }

        public void bindSltList()
        {
            this.hdShopID.Value = this._UserShopID.ToString();
            Chain.BLL.SysShop bllSysShop = new Chain.BLL.SysShop();
            string strWhere = "IsAllianceProgram = 1";
            this.sltShopList.Items.Add(new ListItem("作为独立店铺", "0"));
            DataTable dtSysShop = bllSysShop.GetList(strWhere).Tables[0];
            foreach (DataRow dr in dtSysShop.Rows)
            {
                this.sltShopList.Items.Add(new ListItem(dr["ShopName"].ToString(), dr["ShopID"].ToString()));
            }
            if (base._UserShopID > 1)
            {
                this.rdislms.Attributes.Add("disabled", "disabled");
                this.rdisnotlms.Attributes.Add("disabled", "disabled");
                this.sltShopList.Value = this._UserShopID.ToString();
                this.sltShopList.Attributes.Add("disabled", "disabled");
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.BindShopList(this.GetSearch());
        }

        protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = 1;
            this.NetPagerParameter.PageSize = int.Parse(this.drpPageSize.SelectedValue);
            this.BindShopList(this.GetSearch());
        }

        public string GetSearch()
        {
            string strScarch = "";
            if (this.txtSearch.Text.Trim() != "")
            {
                strScarch = string.Format(" and (ShopName like '%{0}%' or ShopTelephone like '%{0}%' or ShopContactMan like '%{0}%' or ShopAddress like '%{0}%') ", this.txtSearch.Text.Trim());
            }
            return strScarch;
        }

        protected void NetPagerParameter_PageChanging(object src, PageChangingEventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = e.NewPageIndex;
            this.BindShopList(this.GetSearch());
        }

        private void NewMethod()
        {
            if (!PubFunction.curParameter.UsingUnion)
            {
                this.txtSettlementInterval.Value = "36500";
                this.txtShopProportion.Value = "0";
                this.trSettlement.Attributes.Add("style", "display:none;");
                this.rdisnotlms.Checked = true;
                this.trAlliance.Attributes.Add("style", "display:none;");
                this.sltShopList.SelectedIndex = 0;
                this.trSltShop.Attributes.Add("style", "display:none;");
                this.trShopSms.Attributes.Add("style", "display:none;");
                this.trShopPoint.Attributes.Add("style", "display:none;");
                this.BindShopList("");
            }
            else
            {
                StringBuilder strSql = new StringBuilder();
                if (base._UserShopID == 1)
                {
                    strSql.Append(" and FatherShopID = 0 ");
                }
                else
                {
                    strSql.AppendFormat(" and FatherShopID = {0} or ShopID={0}", base._UserShopID);
                }
                this.BindShopList(strSql.ToString());
                Chain.Model.SysShop shop = new Chain.BLL.SysShop().GetModel(base._UserShopID);
                if (!shop.IsAllianceProgram && (shop.ShopID != 1))
                {
                    this.btnShopAdd.Visible = false;
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.chkSMS.Checked = PubFunction.curParameter.bolSms;
                this.bindSltList();
                this.txtIsSendCard.Value = PubFunction.curParameter.bolIsSendCard ? "1" : "0";
                this.txtSmsManage.Value = PubFunction.curParameter.bolShopSmsManage ? "1" : "0";
                this.txtPointManage.Value = PubFunction.curParameter.bolShopPointManage ? "1" : "0";
                this.txtIsSettlement.Value = PubFunction.curParameter.bolIsSettlement ? "1" : "0";
                this.union.Value = PubFunction.curParameter.UsingUnion.ToString();
                this.NewMethod();
            }
        }
    }


